<tagLib name="html" />

<include file="Public:header" />

<div class="container" id="cpcontainer">
    <div class="itemtitle">
        <h3>{$Think.lang.email.title}</h3>
        <ul class="tab1" id="submenu">
            <li class="current"><a href="__URL__/email"><span>{$Think.lang.email.config}</span></a></li>
            <li><a href="__URL__/emailTemplate"><span>{$Think.lang.email.tpl}</span></a></li>
        </ul>
    </div>
    <p class="tips">{$Think.lang.email.config_tips}</p>
    <form name="cpform" method="post" action="__URL__/email">
    <input type="hidden" name="op" value="save" /> 
    <table class="tb tb2" id="config">
        <tr class="nobg"><td colspan="2" class="td27">{$Think.lang.email.mailer_type}</td></tr>
        <tr>
            <td class="vtop rowform">
	            <ul class="nofloat" onmouseover="altStyle(this);">
		            <volist name="mailerTypeRadios" id="vo">
		            <li><input type="radio" name="mailer_type" value="{$key}" <eq name="key" value="$mailerTypeChecked">checked</eq> onclick="switchMailerType(this);" /> {$vo} </li>
		            </volist>
	            </ul>
            </td>
            <td class="vtop tips2"></td>
        </tr>
        <tbody id="smtp" style="display:none">
        <tr class="nobg"><td colspan="2" class="td27">{$Think.lang.email.smtp_host}</td></tr>
        <tr>
            <td class="vtop rowform"><input name="smtp_host" value="{$rs.smtp_host}" type="text" class="txt"  /></td>
            <td class="vtop tips2">{$Think.lang.email.smtp_host_explain}</td>
        </tr>
        <tr class="nobg"><td colspan="2" class="td27">{$Think.lang.email.smtp_port}</td></tr>
        <tr>
            <td class="vtop rowform"><input name="smtp_port" value="{$rs.smtp_port}" type="text" class="txt"  /></td>
            <td class="vtop tips2">{$Think.lang.email.smtp_port_explain}</td>
        </tr>
        <tr class="nobg"><td colspan="2" class="td27">{$Think.lang.email.smtp_encrypt}</td></tr>
        <tr>
            <td class="vtop rowform">
                <html:radio name="smtp_encrypt" radios="encryptRadios" checked="encryptChecked" separator=" " />
            </td>
            <td class="vtop tips2"></td>
        </tr>
        <tr class="nobg"><td colspan="2" class="td27">{$Think.lang.email.smtp_auth}</td></tr>
        <tr>
            <td class="vtop rowform">
                <html:radio name="smtp_auth" radios="authRadios" checked="authChecked" separator=" " onclick="showSmtpAccount(this);" />
            </td>
            <td class="vtop tips2"></td>
        </tr>
        </tbody>
        
        <tbody id="smtp_account" style="display:none;">
        <tr class="nobg"><td colspan="2" class="td27">{$Think.lang.email.smtp_auth_username}</td></tr>
        <tr>
            <td class="vtop rowform"><input name="smtp_auth_username" value="{$rs.smtp_auth_username}" type="text" class="txt" /></td>
            <td class="vtop tips2">{$Think.lang.email.smtp_auth_username_explain}</td>
        </tr>
        <tr class="nobg"><td colspan="2" class="td27">{$Think.lang.email.smtp_auth_password}</td></tr>
        <tr>
            <td class="vtop rowform"><input name="smtp_auth_password" value="{$rs.smtp_auth_password}" type="text" class="txt" /></td>
            <td class="vtop tips2">{$Think.lang.email.smtp_auth_password_explain}</td>
        </tr>
        </tbody>
        
        <tr class="nobg"><td colspan="2" class="td27">{$Think.lang.email.contact_email}</td></tr>
        <tr>
            <td class="vtop rowform"><input name="contact_email" value="{$rs.contact_email}" type="text" class="txt" /></td>
            <td class="vtop tips2">{$Think.lang.email.contact_email_explain}</td>
        </tr>
        <tr class="nobg"><td colspan="2" class="td27">{$Think.lang.email.return_email}</td></tr>
        <tr>
            <td class="vtop rowform"><input name="return_email" value="{$rs.return_email}" type="text" class="txt" /></td>
            <td class="vtop tips2">{$Think.lang.email.return_email_explain}</td>
        </tr>
        <tr class="nobg"><td colspan="2" class="td27">{$Think.lang.email.signature}</td></tr>
        <tr>
            <td class="vtop rowform"><textarea class="tarea" onkeyup="textareasize(this)" name="email_signature" cols="50" rows="6">{$rs.email_signature}</textarea></td>
            <td class="vtop tips2">{$Think.lang.email.signature_explain}</td>
        </tr>
        
        <tr class="nobg">
            <td colspan="15"><div class="fixsel"><input type="submit" class="btn" name="submit" value="{$Think.lang.submit}"></div></td>
        </tr>
        
        <tbody id="check"> 
        <tr><td colspan="2" class="partition">{$Think.lang.email.check_config}</td></tr>
        <tr class="nobg"><td colspan="2" class="td27">{$Think.lang.email.test_from}</td></tr>
        <tr>
            <td class="vtop rowform"><input id="test_from" type="text" name="test_from" value="" class="txt" /></td>
            <td class="vtop tips2"></td>
        </tr>
        <tr class="nobg"><td colspan="2" class="td27">{$Think.lang.email.test_to}</td></tr>
        <tr>
            <td class="vtop rowform"><input id="test_to" type="text" name="test_to" class="txt" /></td>
            <td class="vtop tips2">{$Think.lang.email.test_to_explain}</td>
        </tr>  
        <tr class="nobg">
            <td colspan="15"><div class="fixsel"><input type="button" class="btn" name="submit" value="{$Think.lang.submit}" onclick="sendTestEmail()"></div></td>
        </tr>
        </tbody>
    </table>
    </form>
</div>

<include file="Public:footer" />

<script type="text/javascript">
$(function(){
    var type = '{$rs.mailer_type}';
    var auth = '{$rs.smtp_auth}';
    if(type == 'smtp'){
        $('#smtp').show();
    }
    if( type == 'smtp' && auth == '1'){
    	$('#smtp_account').show();
    }
});

function switchMailerType(obj){
    if($(obj).val() == 'smtp'){
        $('#smtp').show();
    }else{
        $('#smtp').hide();
    }
}

function showSmtpAccount(obj){
    if($(obj).val() == '1'){
        $('#smtp_account').show();
    }else{
        $('#smtp_account').hide();
    }
}

function sendTestEmail(){
    var success = '{$Think.lang.email.test_ok}';
    var failed = '{$Think.lang.email.test_failed}';
    var url = _APP_ +'/Admin/Ajax/sendTestEmail';
    var content = {test_to:$('#test_to').val(),test_from:$('#test_from').val()};
    $.blockUI();
    $.post(url,content,function(data){
        $.unblockUI();
        if(data == '1'){
            alert(success);
        }else{
            alert(failed);
        }
    });
} 
</script>